<script>
// 只在APP时加载
// #ifdef APP-PLUS
import RouterInterceptor from "@/js_sdk/fy-showModal/router-interceptor.js"
// #endif
export default {
	globalData: {
		systemType:'',
		provinceId: 0,
		provinceName: '',
		cityName: '',
		cityId: 0,
		cityIndex: 0,
		openid: '',
		unionid:'',
		sessionKey:'',
		cityTextList: [],	//城市列表
		cityIdList:[],	//城市ID列表
		openAppId:'', // 开放平台appId
	},

	 onLaunch: function() {
		uni.hideTabBar({})
		this.init()
		// 只在APP时加载
		// #ifdef APP-PLUS
		RouterInterceptor();
		// #endif
	},
	//  onShow: function() {
	// 	console.log('App Show')
	// },
	// onHide: function() {
	// 	console.log('App Hide')
	// }
	methods: {
		async init(){
			await this.getMyCity()
			this.getSystemInfo()
			// #ifdef MP-WEIXIN
				console.log('app初始化')
				await this.$getMyUserInfo()
			// #endif

			// #ifdef H5 || APP-PLUS
				uni.setStorageSync('globalUserInfoState', 1)
				uni.setStorageSync('globaUserInfo', {IsFB: "1",
													IsVIP: "1",
													IsYZ: "1",
													Num: "1",
													Openid: "oxOg55KS_7V4SlpwLceWDQD8SKxo",
													Session_key: "j80Zjq3B8soRBn7DXrVXJA==",
													Unionid: "ox9XNwU31IBJwl3TWsmpRXpr3TLU",
													avatarUrl: "https://thirdwx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTJLHhNibLUZuoI8kxPrMH8Sm8fvqwONgWYCeFZAMWKFcQynlhy3OMQRsoHtXa55HbYWpqDQKGqD7mw/132",
													city: "",
													country: "",
													gender: 0,
													language: "zh_CN",
													nickName: "杰",
													province: ""})
				getApp().globalData.openid = 'oxOg55KS_7V4SlpwLceWDQD8SKxo'
				getApp().globalData.unionid = 'ox9XNwU31IBJwl3TWsmpRXpr3TLU'
				getApp().globalData.sessionKey = 'j80Zjq3B8soRBn7DXrVXJA=='
			// #endif
		},

		getMyCity() {
			let that = this
			uni.getLocation({
				type: 'gcj02',
				geocode: true,
				success: (res) => {
					let longitude = res.longitude
					let latitude = res.latitude
					let location = [latitude, longitude]
					let StringLocation = location.toString();
					that.$api.getLocationAddress({
						get_poi: 1,
						key: that.$qqMapKey,
						location: StringLocation
					}).then(res => {
						let getCityName = res.result.address_component.city
						that.$api.getCityList().then(res => {
							let tempCityTextList = [], tempCityIdList = []
							for (let i = 0; i < res.data.CityList.length; i++) {
								let item = res.data.CityList[i];
								// 设置全局的城市列表及城市ID列表
								tempCityTextList.push(item.City)
								tempCityIdList.push(item.ID);
								// 先设置默认城市（首次选择排序第一个）
								if (i == 0) {
									getApp().globalData.cityName = item.City
									getApp().globalData.cityId = item.ID
									getApp().globalData.cityIndex = i
								}
								// 如果找到所在城市信息
								if (item.City == getCityName) {
									getApp().globalData.cityName = item.City
									getApp().globalData.cityId = item.ID
									getApp().globalData.cityIndex = i
								}
							}
							getApp().globalData.cityTextList = tempCityTextList
							getApp().globalData.cityIdList = tempCityIdList
							// #ifdef H5
							that.$isResolve()
							// #endif
							uni.setNavigationBarTitle({
							  title: "百业信息报|" + getApp().globalData.cityName+'网'
							})

						})
					})

				},
				fail: (err) => {
					console.log('获取地理位置失败')
					that.$api.getCityList().then(res => {
						let tempCityTextList = [], tempCityIdList = []
						for (let i = 0; i < res.data.CityList.length; i++) {
							let item = res.data.CityList[i];
							// 设置全局的城市列表及城市ID列表
							tempCityTextList.push(item.City)
							tempCityIdList.push(item.ID);
							// 先设置默认城市（首次选择排序第一个）
							if (i == 0) {
								getApp().globalData.cityName = item.City
								getApp().globalData.cityId = item.ID
								getApp().globalData.cityIndex = i
							}
						}
						getApp().globalData.cityTextList = tempCityTextList
						getApp().globalData.cityIdList = tempCityIdList
						that.$isResolve()
						uni.setNavigationBarTitle({
						  title: "百业信息报|" + getApp().globalData.cityName+'网'
						})

					})
				}
			})
		},
		getSystemInfo() {
			let res = uni.getSystemInfoSync()
			if(res.osName == 'android' || res.osName == 'ios') {
				getApp().globalData.systemType = res.osName
			} else {
				getApp().globalData.systemType = 'pc'
			}
			console.log(getApp().globalData.systemType)
		}
	}
};
</script>

<style lang="scss">
/* 注意要写在第一行，同时给style标签加入lang="scss"属性 */
@import "@/uni_modules/uview-ui/index.scss";
/*每个页面公共css */
.page {
	width: 100%;
	height: 100%;
	background-color: #ffffff;
	z-index: 999;
	/* position: absolute; */
}
.page-block {
	background-color: #ffffff;
}
.line-wapper {
	padding: 0upx 20upx;
}
.line {
	height: 1px;
	background-color: #dbdbdb;
}
.is-fixed {
	position: fixed;
	/* #ifdef H5 */
	top: 88rpx;
	/* #endif */
	/* #ifndef H5 */
	top: 0rpx;
	/* #endif */
	left: 0rpx;
	z-index: 9999;
}
</style>
